#include <..\\standard.hlsli>
#include <..\\WR2Parameters.hlsli>

struct PixelToFrame
{
	float4 Color;
};

PixelToFrame ps_main(VertexToPixel PSIn) : SV_TARGET
{
	PixelToFrame Output = (PixelToFrame) 0;
	float3 N = normalize(PSIn.normal);

	float4 Lay1 = xColoredTexture1_Tex.Sample(Tex1, PSIn.texCoord2.xy);
	float4 Lay2 = xColoredTexture2_Tex.Sample(Tex2, PSIn.texCoord2.zw);
	float4 Lay3 = xColoredTexture3_Tex.Sample(Tex3, PSIn.texCoord3.xy);

	float a = smoothstep(0.4375, 0.5625, PSIn.kBlend.r) * Lay3.a;
	float c = smoothstep(0.4375, 0.5625, PSIn.kBlend.b) * Lay1.a * Lay2.a;
	float ShadowCol = smoothstep(0.4375, 0.5625, 1.0 - PSIn.kBlend.a);

	float diffuseColor = max(0.0f, dot(N, -lightDir)) * 1.8f;
	float modulate = 1.0f;
	float3 TexColor = (Lay1.rgb * (1. - c) + Lay2.rgb * c) * (1. - a) + Lay3.rgb * a;
	Output.Color = float4(TexColor.rgb * (SunColor.rgb * diffuseColor * ShadowCol + PSIn.kColor.rgb) * modulate, 1);
	Output.Color = float4(lerp(Output.Color.rgb, FogColor.rgb, PSIn.texCoord3.z), Output.Color.a);
	//if(paintHighLines)
	//{
	//   if(PSIn.original.y % 5.0f < -0.09f && PSIn.original.y % 5.0f  > -0.31f)
	//   {
	//       Output.Color.rgba  =  float4(Output.Color.xyz * 1.5f,0.50f);
	//   }
	//}

	return Output;
}
